﻿// CControlDlg.cpp: 实现文件
//

#include "pch.h"
#include "SP.h"
#include "CControlDlg.h"
#include "afxdialogex.h"


// CControlDlg 对话框

IMPLEMENT_DYNAMIC(CControlDlg, CDialogEx)

CControlDlg::CControlDlg(CWnd* pParent /*=nullptr*/)
	: CDialogEx(IDD_DLG_CONTROL, pParent)
{

}

CControlDlg::~CControlDlg()
{
}

void CControlDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
	DDX_Control(pDX, IDC_EDIT_X, m_editX);
	DDX_Control(pDX, IDC_EDIT_Y, m_editY);
	DDX_Control(pDX, IDC_EDIT_Z, m_editZ);
	DDX_Control(pDX, IDC_COMPOS, m_ComPos);
	DDX_Control(pDX, IDC_EDIT_STEP, m_Step);
	DDX_Control(pDX, IDC_BTN_MOVE, m_MoveBtn);
	DDX_Control(pDX, IDC_BTN_STOP, m_StopBtn);
}

BOOL CControlDlg::OnInitDialog()
{
	CDialogEx::OnInitDialog();
	SetTimer(TIMER_CONTROL_MOTOR_POSITION,50,NULL);
	m_ComPos.ResetContent();
	m_ComPos.AddString(L"0:待机位");
	m_ComPos.AddString(L"1:取螺丝位置");
	m_ComPos.AddString(L"2:打螺丝位置 1");
	m_ComPos.AddString(L"3:打螺丝位置 2");
	m_ComPos.AddString(L"4:打螺丝位置 3");
	m_ComPos.AddString(L"5:打螺丝位置 4");
	//m_ComPos.AddString(L"5:打螺丝位置 5");
	//m_ComPos.AddString(L"5:打螺丝位置 6");
	/*m_ComPos.AddString(L"6:吐螺丝位置");*/
	m_ComPos.SetCurSel(0);
	return 0;
}


BEGIN_MESSAGE_MAP(CControlDlg, CDialogEx)
	ON_WM_TIMER()
	ON_BN_CLICKED(IDC_BTN_STOP, &CControlDlg::OnBnClickedBtnStop)
	ON_BN_CLICKED(IDC_BTN_MOVE, &CControlDlg::OnBnClickedBtnMove)
	ON_BN_CLICKED(IDC_BTN_XA, &CControlDlg::OnBnClickedBtnXa)
	ON_BN_CLICKED(IDC_BTN_XS, &CControlDlg::OnBnClickedBtnXs)
	ON_BN_CLICKED(IDC_BTN_YA, &CControlDlg::OnBnClickedBtnYa)
	ON_BN_CLICKED(IDC_BTN_YS, &CControlDlg::OnBnClickedBtnYs)
	ON_BN_CLICKED(IDC_BTN_ZA, &CControlDlg::OnBnClickedBtnZa)
	ON_BN_CLICKED(IDC_BTN_ZS, &CControlDlg::OnBnClickedBtnZs)
	ON_BN_CLICKED(IDC_BUTTON2, &CControlDlg::OnBnClickedButton2)
	ON_BN_CLICKED(IDC_BUTTON3, &CControlDlg::OnBnClickedButton3)
	ON_BN_CLICKED(IDC_BUTTON4, &CControlDlg::OnBnClickedButton4)
	ON_BN_CLICKED(IDC_BUTTON5, &CControlDlg::OnBnClickedButton5)
	ON_BN_CLICKED(IDC_BUTTON6, &CControlDlg::OnBnClickedButton6)
	ON_BN_CLICKED(IDC_BUTTON7, &CControlDlg::OnBnClickedButton7)
	ON_BN_CLICKED(IDC_BUTTON8, &CControlDlg::OnBnClickedButton8)
	ON_BN_CLICKED(IDC_BUTTON9, &CControlDlg::OnBnClickedButton9)
	ON_BN_CLICKED(IDC_BTNNIULI, &CControlDlg::OnBnClickedBtnniuli)
END_MESSAGE_MAP()


// CControlDlg 消息处理程序


void CControlDlg::OnTimer(UINT_PTR nIDEvent)
{
	// TODO: 在此添加消息处理程序代码和/或调用默认值
	if (nIDEvent == TIMER_CONTROL_MOTOR_POSITION)
	{
		double nDis = Manager.m_vCMotor[MOTOR_X].m_nCurPositon;
		CString cstr;
		cstr.Format(L"%.1f", nDis);
		m_editX.SetWindowTextW(cstr);
		nDis = Manager.m_vCMotor[MOTOR_Y].m_nCurPositon;
		cstr.Format(L"%.1f", nDis);
		m_editY.SetWindowTextW(cstr);
		nDis = Manager.m_vCMotor[MOTOR_Z].m_nCurPositon;
		cstr.Format(L"%.1f", nDis);
		m_editZ.SetWindowTextW(cstr);
	}
	CDialogEx::OnTimer(nIDEvent);
}


void CControlDlg::OnBnClickedBtnStop()
{
	// TODO: 在此添加控件通知处理程序代码
	Manager.m_vCMotor[MOTOR_X].StopMove();
	Manager.m_vCMotor[MOTOR_Y].StopMove();
	Manager.m_vCMotor[MOTOR_Z].StopMove();
}


void CControlDlg::OnBnClickedBtnMove()
{
	// TODO: 在此添加控件通知处理程序代码
	int n;
	n = m_ComPos.GetCurSel();
	Manager.m_bButtonVal = 200 + n;
}



void CControlDlg::OnBnClickedBtnXa()
{
	// TODO: 在此添加控件通知处理程序代码
	CString cstr;
	m_Step.GetWindowTextW(cstr);
	Manager.m_vCMotor[MOTOR_X].m_sAxisSetting.m_dTargetPos = _ttof(cstr);
	Manager.m_vCMotor[MOTOR_X].MotorStepMove();
}


void CControlDlg::OnBnClickedBtnXs()
{
	// TODO: 在此添加控件通知处理程序代码
	CString cstr;
	m_Step.GetWindowTextW(cstr);
	Manager.m_vCMotor[MOTOR_X].m_sAxisSetting.m_dTargetPos = -_ttof(cstr);
	Manager.m_vCMotor[MOTOR_X].MotorStepMove();
}


void CControlDlg::OnBnClickedBtnYa()
{
	// TODO: 在此添加控件通知处理程序代码
	CString cstr;
	m_Step.GetWindowTextW(cstr);
	Manager.m_vCMotor[MOTOR_Y].m_sAxisSetting.m_dTargetPos = _ttof(cstr);
	Manager.m_vCMotor[MOTOR_Y].MotorStepMove();
}


void CControlDlg::OnBnClickedBtnYs()
{
	// TODO: 在此添加控件通知处理程序代码
	CString cstr;
	m_Step.GetWindowTextW(cstr);
	Manager.m_vCMotor[MOTOR_Y].m_sAxisSetting.m_dTargetPos = -_ttof(cstr);
	Manager.m_vCMotor[MOTOR_Y].MotorStepMove();
}


void CControlDlg::OnBnClickedBtnZa()
{
	// TODO: 在此添加控件通知处理程序代码
	CString cstr;
	m_Step.GetWindowTextW(cstr);
	Manager.m_vCMotor[MOTOR_Z].m_sAxisSetting.m_dTargetPos = _ttof(cstr);
	Manager.m_vCMotor[MOTOR_Z].MotorStepMove();
}


void CControlDlg::OnBnClickedBtnZs()
{
	// TODO: 在此添加控件通知处理程序代码
	CString cstr;
	m_Step.GetWindowTextW(cstr);
	Manager.m_vCMotor[MOTOR_Z].m_sAxisSetting.m_dTargetPos = -_ttof(cstr);
	Manager.m_vCMotor[MOTOR_Z].MotorStepMove();
}

void CControlDlg::OnBnClickedButton2()
{
	// TODO: 在此添加控件通知处理程序代码
	Manager.m_bButtonVal = 200;
}


void CControlDlg::OnBnClickedButton3()
{
	// TODO: 在此添加控件通知处理程序代码
	Manager.m_bButtonVal = 201;
}


void CControlDlg::OnBnClickedButton4()
{
	// TODO: 在此添加控件通知处理程序代码
	Manager.m_bButtonVal = 202;
}


void CControlDlg::OnBnClickedButton5()
{
	// TODO: 在此添加控件通知处理程序代码
	Manager.m_bButtonVal = 203;
}


void CControlDlg::OnBnClickedButton6()
{
	// TODO: 在此添加控件通知处理程序代码
	Manager.m_bButtonVal = 207;
}


void CControlDlg::OnBnClickedButton7()
{
	// TODO: 在此添加控件通知处理程序代码
	Manager.m_bButtonVal = 204;
}


void CControlDlg::OnBnClickedButton8()
{
	// TODO: 在此添加控件通知处理程序代码
	Manager.m_bButtonVal = 205;
}


void CControlDlg::OnBnClickedButton9()
{
	// TODO: 在此添加控件通知处理程序代码
	Manager.m_bButtonVal = 208;
}


void CControlDlg::OnBnClickedBtnniuli()
{
	// TODO: 在此添加控件通知处理程序代码
	Manager.m_bButtonVal = 209;




}
